home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-admin / options.php < prev    next >
Encoding:
PHP Script  |  2004-10-13  |  6.5 KB  |  199 lines

  1. <?php
  2. $title = 'Options';
  3. $this_file = 'options.php';
  4. $parent_file = 'options-general.php';
  5.  
  6. function add_magic_quotes($array) {
  7.     foreach ($array as $k => $v) {
  8.         if (is_array($v)) {
  9.             $array[$k] = add_magic_quotes($v);
  10.         } else {
  11.             $array[$k] = addslashes($v);
  12.         }
  13.     }
  14.     return $array;
  15. }
  16.  
  17. if (!get_magic_quotes_gpc()) {
  18.     $_GET    = add_magic_quotes($_GET);
  19.     $_POST   = add_magic_quotes($_POST);
  20.     $_COOKIE = add_magic_quotes($_COOKIE);
  21. }
  22.  
  23. $wpvarstoreset = array('action','standalone', 'option_group_id');
  24. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  25.     $wpvar = $wpvarstoreset[$i];
  26.     if (!isset($$wpvar)) {
  27.         if (empty($_POST["$wpvar"])) {
  28.             if (empty($_GET["$wpvar"])) {
  29.                 $$wpvar = '';
  30.             } else {
  31.                 $$wpvar = $_GET["$wpvar"];
  32.             }
  33.         } else {
  34.             $$wpvar = $_POST["$wpvar"];
  35.         }
  36.     }
  37. }
  38. if (isset($_GET['option_group_id'])) $option_group_id = (int) $_GET['option_group_id'];
  39. require_once('./optionhandler.php');
  40. $non_was_selected = 0;
  41. if ('' == $_GET['option_group_id']) {
  42.     $option_group_id = 1;
  43.     $non_was_selected = 1;
  44. }
  45.  
  46. switch($action) {
  47.  
  48. case 'update':
  49.     $standalone = 1;
  50.     include_once('./admin-header.php');
  51.     $any_changed = 0;
  52.     
  53.     // iterate through the list of options in this group
  54.     // pull the vars from the post
  55.     // validate ranges etc.
  56.     // update the values
  57.     if (!$_POST['page_options']) {
  58.         foreach ($_POST as $key => $value) {
  59.             $option_names[] = "'$key'";
  60.         }
  61.         $option_names = implode(',', $option_names);
  62.     } else {
  63.         $option_names = stripslashes($_POST['page_options']);
  64.     }
  65.  
  66.     $options = $wpdb->get_results("SELECT $tableoptions.option_id, option_name, option_type, option_value, option_admin_level FROM $tableoptions WHERE option_name IN ($option_names)");
  67. //    die(var_dump($options));
  68.  
  69. // HACK
  70. // Options that if not there have 0 value but need to be something like "closed"
  71. $nonbools = array('default_ping_status', 'default_comment_status');
  72.     if ($options) {
  73.         foreach ($options as $option) {
  74.             // should we even bother checking?
  75.             if ($user_level >= $option->option_admin_level) {
  76.                 $old_val = stripslashes($option->option_value);
  77.                 $new_val = $_POST[$option->option_name];
  78.                 if (!$new_val) {
  79.                     if (3 == $option->option_type)
  80.                         $new_val = '';
  81.                     else
  82.                         $new_val = 0;
  83.                 }
  84.                 if( in_array($option->option_name, $nonbools) && $new_val == 0 ) $new_value = 'closed';
  85.                 if ($new_val !== $old_val) {
  86.                     $query = "UPDATE $tableoptions SET option_value = '$new_val' WHERE option_name = '$option->option_name'";
  87.                     $result = $wpdb->query($query);
  88.                     //if( in_array($option->option_name, $nonbools)) die('boo'.$query);
  89.                     if (!$result) {
  90.                         $db_errors .= sprintf(__(" SQL error while saving %s. "), $this_name);
  91.                     } else {
  92.                         ++$any_changed;
  93.                     }
  94.                 }
  95.             }
  96.         } // end foreach
  97.         unset($cache_settings); // so they will be re-read
  98.         get_settings('siteurl'); // make it happen now
  99.     } // end if options
  100.     
  101.     if ($any_changed) {
  102.         $message = sprintf(__('%d setting(s) saved... '), $any_changed);
  103.     }
  104.     
  105.     if (($dB_errors != '') || ($validation_message != '')) {
  106.         if ($message != '') {
  107.             $message .= '<br />';
  108.         }
  109.         $message .= $dB_errors . '<br />' . $validation_message;
  110.     }
  111.  
  112.     $referred = str_replace(array('&updated=true', '?updated=true') , '', $_SERVER['HTTP_REFERER']);
  113.      if (strstr($referred, '?')) $goback = $referred . '&updated=true';
  114.     else $goback = str_replace('?updated=true', '', $_SERVER['HTTP_REFERER']) . '?updated=true';
  115.     $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
  116.     header('Location: ' . $goback);
  117.     break;
  118.  
  119. default:
  120.     $standalone = 0;
  121.     include_once("./admin-header.php");
  122.     if ($user_level <= 6) {
  123.         die(__("You have do not have sufficient permissions to edit the options for this blog."));
  124.     }
  125. ?>
  126.  
  127. <?php
  128. if ($non_was_selected) { // no group pre-selected, display opening page
  129. ?>
  130. <div class="wrap">
  131. <dl>
  132. <?php
  133.     //iterate through the available option groups. output them as a definition list.
  134.     $option_groups = $wpdb->get_results("SELECT group_id, group_name, group_desc, group_longdesc FROM $tableoptiongroups ORDER BY group_id");
  135.     foreach ($option_groups as $option_group) {
  136.         echo("  <dt><a href=\"$this_file?option_group_id={$option_group->group_id}\" title=\"{$option_group->group_desc}\">{$option_group->group_name}</a></dt>\n");
  137.         $current_long_desc = $option_group->group_longdesc;
  138.         if ($current_long_desc == '') {
  139.             $current_long_desc = __('No help for this group of options.');
  140.         }
  141.         echo("  <dd>{$option_group->group_desc}: $current_long_desc</dd>\n");
  142.     } // end for each group
  143. ?>
  144.   <dt><a href="options-permalink.php"><?php _e('Permalinks') ?></a></dt>
  145.   <dd><?php _e('Permanent link configuration') ?></dd>
  146. </dl>
  147. </div>
  148. <?php    
  149.  
  150. } else { //there was a group selected.
  151. include('options-head.php');
  152. ?>
  153.  
  154. <div class="wrap">
  155.   <h2><?php echo $current_desc; ?></h2>
  156.   <form name="form" action="<?php echo $this_file; ?>" method="post">
  157.   <input type="hidden" name="action" value="update" />
  158.   <input type="hidden" name="option_group_id" value="<?php echo $option_group_id; ?>" />
  159.   <table width="90%" cellpadding="2" cellspacing="2" border="0">
  160. <?php
  161. //Now display all the options for the selected group.
  162. if ('all' == $_GET['option_group_id']) :
  163. $options = $wpdb->get_results("SELECT * FROM $tableoptions LEFT JOIN $tableoptiongroup_options ON $tableoptions.option_id = $tableoptiongroup_options.option_id ORDER BY option_name");
  164. else :
  165. $options = $wpdb->get_results("
  166. SELECT 
  167. $tableoptions.option_id, option_name, option_type, option_value, option_width, option_height, option_description, option_admin_level 
  168. FROM $tableoptions  LEFT JOIN $tableoptiongroup_options ON $tableoptions.option_id = $tableoptiongroup_options.option_id
  169. WHERE group_id = $option_group_id
  170. ORDER BY seq
  171. ");
  172. endif;
  173.  
  174. foreach ($options as $option) :
  175.     if ('all' == $_GET['option_group_id']) $option->option_type = 3;
  176.     echo "\t<tr><td width='10%' valign='top'>" . get_option_widget($option, ($user_level >= $option->option_admin_level), '</td><td width="15%" valign="top" style="border: 1px solid #ccc">');
  177.     echo "\t</td><td  valign='top' class='helptext'>$option->option_description</td></tr>\n";
  178. endforeach;
  179. ?>
  180.   </table>
  181. <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Settings »') ?>" /></p>
  182.   </form>
  183. </div>
  184.  
  185. <div class="wrap">
  186. <?php
  187. if ($current_long_desc != '') {
  188.     echo $current_long_desc;
  189. }
  190. ?>
  191. </div>
  192. <?php
  193. } // end else a group was selected
  194. break;
  195. } // end switch
  196.  
  197. include('admin-footer.php');
  198. ?>
  199.